﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Scap.Info;
using Scap.Data;

namespace Scap.Web.Controllers.Admin
{
    public class ScapDepartmentEmployeeAdminController : Controller
    {
        private ScapData db = new ScapData();

        //
        // GET: /ScapDepartmentEmployeeAdmin/

        public ActionResult Index()
        {
            var departmentemployees = db.DepartmentEmployees.Include(s => s.Deparment).Include(s => s.Employee).Include(s => s.Role).Include(s => s.EmploymentType).Include(s => s.EmploymentStatus);
            return View(departmentemployees.ToList());
        }

        //
        // GET: /ScapDepartmentEmployeeAdmin/Details/5

        public ActionResult Details(int id = 0)
        {
            ScapDepartmentEmployee scapdepartmentemployee = db.DepartmentEmployees.Find(id);
            if (scapdepartmentemployee == null)
            {
                return HttpNotFound();
            }
            return View(scapdepartmentemployee);
        }

        //
        // GET: /ScapDepartmentEmployeeAdmin/Create

        public ActionResult Create()
        {
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name");
            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Identification");
            ViewBag.RoleId = new SelectList(db.EmployeeRoles, "Id", "Name");
            ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Name");
            ViewBag.EmploymentStatusId = new SelectList(db.EmployeeStatus, "Id", "Name");
            return View();
        }

        //
        // POST: /ScapDepartmentEmployeeAdmin/Create

        [HttpPost]
        public ActionResult Create(ScapDepartmentEmployee scapdepartmentemployee)
        {
            if (ModelState.IsValid)
            {
                db.DepartmentEmployees.Add(scapdepartmentemployee);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", scapdepartmentemployee.DepartmentId);
            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Identification", scapdepartmentemployee.EmployeeId);
            ViewBag.RoleId = new SelectList(db.EmployeeRoles, "Id", "Name", scapdepartmentemployee.RoleId);
            ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Name", scapdepartmentemployee.EmployeeTypeId);
            ViewBag.EmploymentStatusId = new SelectList(db.EmployeeStatus, "Id", "Name", scapdepartmentemployee.EmploymentStatusId);
            return View(scapdepartmentemployee);
        }

        //
        // GET: /ScapDepartmentEmployeeAdmin/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ScapDepartmentEmployee scapdepartmentemployee = db.DepartmentEmployees.Find(id);
            if (scapdepartmentemployee == null)
            {
                return HttpNotFound();
            }
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", scapdepartmentemployee.DepartmentId);
            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Identification", scapdepartmentemployee.EmployeeId);
            ViewBag.RoleId = new SelectList(db.EmployeeRoles, "Id", "Name", scapdepartmentemployee.RoleId);
            ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Name", scapdepartmentemployee.EmployeeTypeId);
            ViewBag.EmploymentStatusId = new SelectList(db.EmployeeStatus, "Id", "Name", scapdepartmentemployee.EmploymentStatusId);
            return View(scapdepartmentemployee);
        }

        //
        // POST: /ScapDepartmentEmployeeAdmin/Edit/5

        [HttpPost]
        public ActionResult Edit(ScapDepartmentEmployee scapdepartmentemployee)
        {
            if (ModelState.IsValid)
            {
                db.Entry(scapdepartmentemployee).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", scapdepartmentemployee.DepartmentId);
            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Identification", scapdepartmentemployee.EmployeeId);
            ViewBag.RoleId = new SelectList(db.EmployeeRoles, "Id", "Name", scapdepartmentemployee.RoleId);
            ViewBag.EmployeeTypeId = new SelectList(db.EmployeeTypes, "Id", "Name", scapdepartmentemployee.EmployeeTypeId);
            ViewBag.EmploymentStatusId = new SelectList(db.EmployeeStatus, "Id", "Name", scapdepartmentemployee.EmploymentStatusId);
            return View(scapdepartmentemployee);
        }

        //
        // GET: /ScapDepartmentEmployeeAdmin/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ScapDepartmentEmployee scapdepartmentemployee = db.DepartmentEmployees.Find(id);
            if (scapdepartmentemployee == null)
            {
                return HttpNotFound();
            }
            return View(scapdepartmentemployee);
        }

        //
        // POST: /ScapDepartmentEmployeeAdmin/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            ScapDepartmentEmployee scapdepartmentemployee = db.DepartmentEmployees.Find(id);
            db.DepartmentEmployees.Remove(scapdepartmentemployee);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}